using System;

using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Hardware;

namespace Project
{
    class WindowWindow:Window
    {
        private Window windowsWindow;
        Canvas canvas = new Canvas();

        public WindowWindow(Window mw)
        {
            windowsWindow = new Window();
            windowsWindow.Height = SystemMetrics.ScreenHeight;
            windowsWindow.Width = SystemMetrics.ScreenWidth;

            createWindow();
        }

        public void createWindow()
        {
           
            Image image_kitchen_closed = new Image(Resources.GetBitmap(Resources.BitmapResources.kitchen));
            image_kitchen_closed.HorizontalAlignment = HorizontalAlignment.Center;
            image_kitchen_closed.VerticalAlignment = VerticalAlignment.Center;
            Image image_living_closed = new Image(Resources.GetBitmap(Resources.BitmapResources.living_room));
            image_living_closed.HorizontalAlignment = HorizontalAlignment.Center;
            image_living_closed.VerticalAlignment = VerticalAlignment.Center;
            Image image_bedroom_closed = new Image(Resources.GetBitmap(Resources.BitmapResources.bedroom));
            image_bedroom_closed.HorizontalAlignment = HorizontalAlignment.Center;
            image_bedroom_closed.VerticalAlignment = VerticalAlignment.Center;
            Image image_bathroom_closed = new Image(Resources.GetBitmap(Resources.BitmapResources.bathroom));
            image_bathroom_closed.HorizontalAlignment = HorizontalAlignment.Center;
            image_bathroom_closed.VerticalAlignment = VerticalAlignment.Center;

            Image image_kitchen_opened = new Image(Resources.GetBitmap(Resources.BitmapResources.kitchen_red));
            image_kitchen_opened.HorizontalAlignment = HorizontalAlignment.Center;
            image_kitchen_opened.VerticalAlignment = VerticalAlignment.Center;
            Image image_living_opened = new Image(Resources.GetBitmap(Resources.BitmapResources.living_room_red));
            image_living_opened.HorizontalAlignment = HorizontalAlignment.Center;
            image_living_opened.VerticalAlignment = VerticalAlignment.Center;
            Image image_bedroom_opened = new Image(Resources.GetBitmap(Resources.BitmapResources.bedroom_red));
            image_bedroom_opened.HorizontalAlignment = HorizontalAlignment.Center;
            image_bedroom_opened.VerticalAlignment = VerticalAlignment.Center;
            Image image_bathroom_opened = new Image(Resources.GetBitmap(Resources.BitmapResources.bathroom_red));
            image_bathroom_opened.HorizontalAlignment = HorizontalAlignment.Center;
            image_bathroom_opened.VerticalAlignment = VerticalAlignment.Center;

            Panel pan_kitchen = new Panel();
            Panel pan_living = new Panel();
            Panel pan_bedroom = new Panel();
            Panel pan_bathroom = new Panel();

            #region image location
            if (Drivers.getInstance().window_kitchen.Read())
            {
                pan_kitchen.Children.Add(image_kitchen_closed);
            }
            else
            {
                pan_kitchen.Children.Add(image_kitchen_opened);
            }
            Canvas.SetTop(pan_kitchen, 0);
            Canvas.SetLeft(pan_kitchen, 0);
            canvas.Children.Add(pan_kitchen);

            if (Drivers.getInstance().window_living.Read())
            {
                pan_living.Children.Add(image_living_closed);
            }
            else
            {
                pan_living.Children.Add(image_living_opened);
            }
            Canvas.SetTop(pan_living, 0);
            Canvas.SetRight(pan_living, 0);
            canvas.Children.Add(pan_living);

            if (Drivers.getInstance().window_bedroom.Read())
            {
                pan_bedroom.Children.Add(image_bedroom_closed);
            }
            else
            {
                pan_bedroom.Children.Add(image_bedroom_opened);
            }
            Canvas.SetTop(pan_bedroom, 2 * windowsWindow.Height / 5);
            Canvas.SetLeft(pan_bedroom, 0);
            canvas.Children.Add(pan_bedroom);

            if (Drivers.getInstance().window_bathroom.Read())
            {
                pan_bathroom.Children.Add(image_bathroom_closed);
            }
            else
            {
                pan_bathroom.Children.Add(image_bathroom_opened);
            }
            Canvas.SetTop(pan_bathroom, 2 * windowsWindow.Height / 5);
            Canvas.SetRight(pan_bathroom, 0);
            canvas.Children.Add(pan_bathroom);
            #endregion

            Image image_return = new Image(Resources.GetBitmap(Resources.BitmapResources.imreturn));
            image_return.HorizontalAlignment = HorizontalAlignment.Center;
            image_return.VerticalAlignment = VerticalAlignment.Center;
            SimpleButton button_return = new SimpleButton(image_return, windowsWindow.Width / 2, windowsWindow.Height / 5);
            button_return.BackColor = Colors.White;
            Canvas.SetBottom(button_return, 0);
            Canvas.SetRight(button_return, 0);
            canvas.Children.Add(button_return);

            button_return.Click += new EventHandler(returnButton_Click);

            windowsWindow.Child = canvas;
            windowsWindow.Visibility = Visibility.Visible;
           
        }

        void returnButton_Click(object sender, EventArgs evt)
        {
            windowsWindow.Close();
        }
    }
}
